from pathlib import Path

from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.middleware.cors import CORSMiddleware

import funccollect.config as fc
from .router import api_router

__origins = [
        "http://localhost",
        "http://localhost:8080",
        f"http://{fc.get_ip_port()}",
        f"http://localhost:{fc.g_port}",
    ]


def __creat_app():
    app = FastAPI()
    app.include_router(api_router)
    app.mount('/static',
              StaticFiles(directory=str(Path(__file__).parent / Path('static'))),
              name='css-js-neko')
    app.add_middleware(CORSMiddleware,
                       allow_origins=__origins,
                       allow_credentials=True,
                       allow_methods=["*"],
                       allow_headers=["*"],
                       )
    return app
